﻿using Furion.DependencyInjection;

namespace Events;

/// <summary>
/// EventBus通用函数
/// </summary>
public class Common : ITransient
{
    private readonly ISqlSugarClient db;

    public Common(ISqlSugarClient db)
    {
        this.db = db;
    }

    /// <summary>
    /// 获取订单信息通过缓存
    /// </summary>
    /// <param name="orderNo"></param>
    /// <returns></returns>
    public async Task<Entity.Order> GetOrder(string orderNo)
    {
        return await db.Queryable<Entity.Order>().WithCache("orderQuery", 60).FirstAsync(x => x.OrderNo == orderNo);
    }

    /// <summary>
    /// 检测是否是指定类型的订单
    /// </summary>
    /// <param name="orderNo"></param>
    /// <param name="orderType"></param>
    /// <returns></returns>
    public async Task<bool> GetOrderType(string orderNo , Entity.OrderType orderType)
    {
        var order = await GetOrder(orderNo);

        return order.OrderType == orderType;
    }
}
